// haojk/pages/setSubbranch/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      shopname: '',
      shopdesc: '',
      shoplogo:'',
      isShowLogo:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
      var $that = this;
      var memberinfo = wx.getStorageSync('memberinfo');
   
      if (memberinfo.shoplogo){
          $that.setData({ isShowLogo: true,});
      }
      $that.setData({
          shopname: memberinfo.shopname,
          shoplogo: memberinfo.shoplogo,
          shopdesc: memberinfo.shopdesc,

      })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
     
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  confirm:function(){
      var $that = this;
      app.util.request({
          url: 'entry/wxapp/SetShopName',
          showLoading: true,
          data: {
              "m": 'nets_haojk',
              // "from_uid": e.data
              "from_uid": "0",
              shopname: $that.data.shopname,
              shopdesc: $that.data.shopdesc,
              shoplogo: $that.data.shoplogo
    
          },
          method: 'post',
          success: function (response) {
         
            if(response.data){
                wx.showModal({
                    title: '提示',
                    content: '店铺设置成功',
                    success: function (res) {
                        if (res.confirm) {
                          
                        } else if (res.cancel) {
                          
                        }
                    }
                })
            }
             
          }
      });
  },
  shopdescChange:function(e){
  
    this.setData({
        shopdesc:e.detail.value
    })
  },
  shopnameChange: function (e) {
  
      this.setData({
          shopname: e.detail.value
      })
  },
  upLoadImg:function(){
      var $that=this;
      wx.chooseImage({
          count: 1, // 默认9
          success: function (res) {
              // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
            if(res){
                var tempFilePaths = res.tempFilePaths;
                var filepath = tempFilePaths[0];
              
                $that.setData(
                    {
                       
                        isShowLogo: true
                    },
                );
             
                wx.uploadFile({
                  url: app.util.url("entry/wxapp/Upload", { "m": 'nets_haojk' }), //仅为示例，非真实的接口地址
                    filePath: filepath,
                    name:'upfile',

                    success: function (res) {
                      
                      
                        var jsonRes = JSON.parse(res.data);
                      
                        $that.setData(
                            { shoplogo: jsonRes.data}
                        )

                        //do something
                    }
                })
            }
             
          }
      })
  }
  
})